package com.cyt.web.controller.work.wb;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.base.util.StringUtils;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.BaseController;
import com.cyt.work.wb.model.po.WbNotice;
import com.cyt.work.wb.model.vo.WbNoticeVo;
import com.cyt.work.wb.service.WbNoticeService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 维保模块-通知公告表控制层
 *
 * @author dingxu
 * @date 2019-12-6 8:18:44
 */
@RestController
public class WbNoticeController extends BaseController {

    @Resource
    private WbNoticeService wbNoticeService;

    /**
     * 统一跳转
     *
     * @return Model
     * @author dingxu
     * @date 2019-12-6 8:18:44
     */
    @RequestMapping("/work/wb/wbnotice/{pageName}")
    public ModelAndView goPage(@PathVariable("pageName") String pageName, String applyId) {
        ModelAndView view = new ModelAndView("/work/wb/wbnotice/"+pageName);
        view.addObject("applyId", applyId);
        return view;
    }

    /**
     * 分页查询
     *
     * @param wbNoticeVo 接受参数对象
     * @param page 当前页面
     * @param limit 页面数量
     * @return ReturnResult
     * @author dingxu
     * @date 2019-12-6 8:18:44
     */
    @BaseLog(module = "维保模块", classz = "通知公告表", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wbnotice/page", method = RequestMethod.POST)
    public ReturnResult page(WbNoticeVo wbNoticeVo, int page, int limit) {
        return wbNoticeService.page(wbNoticeVo, page, limit);
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param id 主键
     * @return ReturnResult
     * @author dingxu
     * @date 2019-12-6 8:18:44
     */
    @BaseLog(module = "维保模块", classz = "通知公告表", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wbnotice/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id,String applyId) {
        ModelAndView view = new ModelAndView("work/wb/wbnotice/wbNoticeEdit");
        WbNotice wbNotice=new WbNotice();
        if (StringUtils.isNotBlank(id)) {
            wbNotice= wbNoticeService.selectByPrimaryKey(id);
        }
        wbNotice.setApplyId(applyId);
        view.addObject(wbNotice);
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request 请求对象
     * @param wbNoticeVo 接受参数对象
     * @return ReturnResult
     * @author dingxu
     * @date 2019-12-6 8:18:44
     */
    @BaseLog(module = "维保模块", classz = "通知公告表", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wbnotice/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, WbNoticeVo wbNoticeVo) {
        return wbNoticeService.addOrUpdate(wbNoticeVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request 请求对象
     * @param wbNoticeVo 接受参数对象
     * @return ReturnResult
     * @author dingxu
     * @date 2019-12-6 8:18:44
     */
    @BaseLog(module = "维保模块", classz = "通知公告表", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wbnotice/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, WbNoticeVo wbNoticeVo) {
        return wbNoticeService.remove(wbNoticeVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件物理删除
     *
     * @param request 请求对象
     * @param wbNoticeVo 接受参数对象
     * @return ReturnResult
     * @author dingxu
     * @date 2019-12-6 8:18:44
     */
    @BaseLog(module = "维保模块", classz = "通知公告表", methods = "物理对象对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/wb/wbnotice/delete", method = RequestMethod.GET)
    public ReturnResult delete(HttpServletRequest request, WbNoticeVo wbNoticeVo) {
        return wbNoticeService.delete(wbNoticeVo, acceptCurrentUser(request));
    }
}